/*
 * This file is part of ELCube.
 *
 * ELCube is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Affero General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * ELCube is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Affero General Public License for more details.
 *
 * You should have received a copy of the GNU Affero General Public License
 * along with ELCube.  If not, see <https://www.gnu.org/licenses/>.
 */
package cn.nkpro.elcube.bigdata;

import cn.nkpro.elcube.bigdata.service.ClickHouseService;
import cn.nkpro.elcube.bigdata.service.ElasticSearchService;
import cn.nkpro.elcube.bigdata.service.JdbcMySqlService;
import cn.nkpro.elcube.bigdata.service.impl.ClickHouseSearchServiceImpl;
import cn.nkpro.elcube.bigdata.service.impl.ElasticSearchServiceImpl;
import cn.nkpro.elcube.bigdata.service.impl.JdbcMySqlSearchServiceImpl;
import cn.nkpro.elcube.cloud.NkAbstractDubboConsumerAutoRegistrar;
import cn.nkpro.elcube.data.clickhouse.ClickHouseTemplate;
import cn.nkpro.elcube.data.jdbc.NkJdbcProperties;
import org.apache.dubbo.config.annotation.DubboService;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Import;

@Configuration
@MapperScan(basePackages = {
        "cn.nkpro.elcube.bigdata.gen",
})
public class NkBigDataConfig {


    /**
     * 开始配置云服务
     */

    @ConditionalOnProperty(
            prefix = "dubbo",
            name = {"enabled"},
            matchIfMissing = true
    )
    @Configuration
    @Import(DubboConsumerAutoRegistrar.class)
    public static class NkDocEngineCloudConfig {}
    static class DubboConsumerAutoRegistrar extends NkAbstractDubboConsumerAutoRegistrar {
        @Override
        protected Class<?>[] registrarClass() {
            return new Class[]{
                    ClickHouseService.class,
                    ElasticSearchService.class,
                    JdbcMySqlService.class
            };
        }
    }

    @ConditionalOnBean(ClickHouseTemplate.class)
    @Bean
    @DubboService
    public ClickHouseSearchServiceImpl ClickHouseService(){
        return new ClickHouseSearchServiceImpl();
    }

    @Bean
    @DubboService
    public ElasticSearchService ElasticSearchService(){
        return new ElasticSearchServiceImpl();
    }

    @ConditionalOnBean(NkJdbcProperties.class)
    @Bean
    @DubboService
    public JdbcMySqlSearchServiceImpl JdbcMySqlService(){
        return new JdbcMySqlSearchServiceImpl();
    }
}